
/**
 * @author LKQ
 * @date 2021/12/11 9:26
 * @description 异或运算，因为任何数和其自身做异或运算，结果是 0；任何数和 00 做异或运算，结果仍然是原来的数，
 * 且异或运算满足交换律和结合律。
 */
public class Solution1 {
    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        int[] nums = {4, 2, 1, 2, 1};
        solution1.singleNumber(nums);
    }
    public int singleNumber(int[] nums) {
        int single = 0;
        for (int num: nums) {
            single ^= num;
        }
        return single;
    }
}
